package top.ldkxingzhe.ldksettings

import android.content.Intent
import android.support.v7.app.AppCompatActivity
import android.os.Bundle
import android.support.v7.widget.LinearLayoutManager
import android.support.v7.widget.RecyclerView
import kotlinx.android.synthetic.main.activity_main.*
import top.ldkxingzhe.ldksettings.actions.PMHelper
import top.ldkxingzhe.ldksettings.adapters.InstalledAppsAdapter
import top.ldkxingzhe.ldksettings.entities.InstalledInfoHolder

class MainActivity : AppCompatActivity() {

    private val TAG = "MainActivity";
    lateinit var recyclerView: RecyclerView

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
        recyclerView = recyclerview
        recyclerView.layoutManager = LinearLayoutManager(this)
        val pmHelper = PMHelper(this)
        val installedInfo = pmHelper.installedNonSystemApps().map { InstalledInfoHolder(it) }
        val adapter = InstalledAppsAdapter(installedInfo)
        recyclerView.adapter = adapter
        adapter.onItemClickListener = {
            _, item ->
            val intent = Intent(this, DetailActivity::class.java)
            intent.putExtra("app", item.applicationInfo.packageName)
            startActivity(intent)
        }
    }
}
